home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / win / geticon.c next >
Encoding:
C/C++ Source or Header  |  1998-12-02  |  2.4 KB  |  100 lines

  1. #ifndef lint    )Ø    *LSid = "$Id: geticon.c,v 1.2 1998/12/01 20:09:38 lhecking Exp $";
  2. #endif
  3.  
  4. /* geticon.c */
  5. /* extract Borland ascii format icons from resource script */
  6. /* and write as Microsoft binary format .ICO files */
  7. /* Russell Lang 1992-12-20 */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. /* HBB 980809: naming a variable 'inline' is a bad idea, these days. Too
  15.  * many compilers use it as a keyword... Changed to 'inputline' */
  16. #define MAXLINE 255
  17. FILE *rcfile;
  18. char inputline[MAXLINE+1];
  19. char *tok1, *tok2, *tok3;
  20. char *p;
  21. char iconname[MAXLINE+1];
  22. FILE *iconfile;
  23. int line;
  24.  
  25. int htoi(char ch)
  26. {
  27.     ch = toupper(ch);
  28.     if (ch < '0')
  29.         return(0);
  30.     else if (ch <= '9')
  31.         return((int)(ch - '0'));
  32.     else if (ch < 'A')
  33.         return(0);
  34.     else if (ch <= 'F')
  35.         return((int)(ch - 'A' + 10));
  36.     return(0);
  37. }
  38.  
  39. void
  40. geticon(void)
  41. {
  42. char ch;
  43.     fgets(inputline,MAXLINE,rcfile);
  44.     line++;
  45.     if (strncmp(inputline,"BEGIN",5)) {
  46.         fprintf(stderr,"Expecting BEGIN at line %d\n",line);
  47.         exit(3);
  48.     }
  49.     if ( (iconfile = fopen(iconname,"wb")) == (FILE *)NULL) {
  50.         fprintf(stderr,"Can't open ICON file %s\n",iconname);
  51.         exit(4);
  52.     }
  53.     fgets(inputline,MAXLINE,rcfile);
  54.     line++;
  55.     while (strncmp(inputline,"END",3) && !feof(rcfile)) {
  56.         for (p = inputline; *p && (*p==' ' || *p == '\t' || *p=='\''); p++);
  57.         while (isxdigit(*p)) {
  58.             ch = htoi(*p++)<<4;
  59.             ch += htoi(*p++);
  60.             fputc(ch, iconfile);
  61.             p++;
  62.         }
  63.         fgets(inputline,MAXLINE,rcfile);
  64.         line++;
  65.     }
  66.     fclose(iconfile);
  67. }
  68.  
  69. int
  70. main(int argc, char *argv[])
  71. {
  72.     if ((argc < 2) || (argc > 3)) {
  73.     fprintf(stderr,"Usage:  geticon  resource_file [icon_directory]\n");
  74.     return(1);
  75.     }
  76.     if ( (rcfile = fopen(argv[1],"r")) == (FILE *)NULL) {
  77.     fprintf(stderr,"Can't open RC file\n");
  78.     return(2);
  79.     }
  80.     line = 0;
  81.     while (fgets(inputline,MAXLINE,rcfile)) {
  82.         line++;
  83.     tok1 = strtok(inputline," \t\r\n");
  84.     tok2 = strtok(NULL," \t\r\n");
  85.     tok3 = strtok(NULL," \t\r\n");
  86.     if (tok2 && !strcmp(tok2,"ICON") && (tok3 == (char *)NULL)) {
  87.             iconname[0] = '\0';
  88.         if (argc == 3) {
  89.                 strcpy(iconname,argv[2]);
  90.                 strcat(iconname,"\\");
  91.             }
  92.             strcat(iconname,tok1);
  93.             strcat(iconname,".ico");
  94.         fprintf(stdout,"%s\n",iconname);
  95.         geticon();
  96.     }
  97.     }
  98.     return (0);
  99. }
  100.